﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainSimulator.Interfaces;
using System.Drawing;

namespace TrainSimulator.Model.Track
{
    public class CurveTrack : TrackGeometry
    {
        private double _angle;
        private double _radius;
        private float _centerX, _centerY;

        /// <summary>
        /// Choose the startpoint from previuos track endpoint
        /// </summary>
        public CurveTrack(ITrack track, PointF startPoint, double direction, double orientation, Bitmap image)
            : base(track, startPoint, direction, orientation, image)
        {
            _angle = DegreeToRadian(track.Angle);
            _radius = track.Length / _angle;
            _centerX = this.StartPoint.X - (float)(_radius * Math.Cos(this.Direction));
            _centerY = this.StartPoint.Y - (float)(_radius * Math.Sin(this.Direction));

            this.EndPoint = GetPosition(Track.Length);
        }

        private PointF GetPosition(double lengthOfTrack)
        {
            PointF p = new PointF();
            double posAngle = GetAngle(lengthOfTrack);
            p.X = _centerX + (float)(_radius * Math.Cos(posAngle));
            p.Y = _centerY + (float)(_radius * Math.Sin(posAngle));
            return p;
        }

        //private double GetAngle(double lengthOfTrack)
        //{
        //    return this.Direction + lengthOfTrack / _radius;
        //}
    }
}
